<template>
  <div class="cloud-lounge-welcome">
    <!-- 星空背景 -->
    <div class="welcome-background">
      <div class="starry-background"></div>
    </div>
    
    <!-- 标题区域 -->
    <div class="title-section">
      <h1 class="welcome-title" @click="handleTitleClick">欢迎来到云上会客厅</h1>
      <p class="welcome-subtitle" @click="handleSubtitleClick">赋能双鸭山:家底清,服务优,产业兴</p>
    </div>
    
    <!-- 功能图片区域 -->
    <div class="features-section">
      <div class="feature-image green-image" @click="goToCloudRoaming">
        <img src="../assets/green_btn_bg.png" alt="云上漫游" class="feature-img" />
        <div class="feature-content">
          <img src="../assets/图片 7@2x.png" alt="云上漫游图标" class="feature-icon" />
          <div class="feature-text">云上漫游</div>
        </div>
      </div>
      
      <div class="feature-image blue1-image">
        <img src="../assets/blue_btn_bg_1.png" alt="视频洽谈" class="feature-img" />
        <div class="feature-content">
          <img src="../assets/图片 8@2x.png" alt="视频洽谈图标" class="feature-icon" />
          <div class="feature-text">视频洽谈</div>
        </div>
      </div>
      
      <div class="feature-image blue2-image">
        <img src="../assets/blue_btn_bg_2.png" alt="政策兑付" class="feature-img" />
        <div class="feature-content">
          <img src="../assets/图片 9@2x.png" alt="政策兑付图标" class="feature-icon" />
          <div class="feature-text">政策兑付</div>
        </div>
      </div>
      
      <div class="feature-image pink-image">
        <img src="../assets/pink_btn_bg.png" alt="电子签约" class="feature-img" />
        <div class="feature-content">
          <img src="../assets/图片 10@2x.png" alt="电子签约图标" class="feature-icon" />
          <div class="feature-text">电子签约</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CloudLoungeWelcome',
  mounted() {
    this.loadBackgroundImage();
    this.loadCardImages();
    this.handleResize();
    window.addEventListener('resize', this.handleResize);
  },
  beforeUnmount() {
    window.removeEventListener('resize', this.handleResize);
  },
  methods: {
    loadBackgroundImage() {
      // 预加载背景图片
      const img = new Image();
      img.src = require('./star_background.png');
      img.onload = () => {
        console.log('背景图片加载成功');
      };
      img.onerror = () => {
        console.warn('背景图片加载失败，使用备用方案');
      };
    },
    loadCardImages() {
      // 预加载所有功能图片
      const images = [
        require('../assets/green_btn_bg.png'),
        require('../assets/blue_btn_bg_1.png'), 
        require('../assets/pink_btn_bg.png'),
        require('../assets/blue_btn_bg_2.png')
      ];
      
      // 预加载所有图标图片
      const iconImages = [
        require('../assets/图片 7@2x.png'),
        require('../assets/图片 8@2x.png'),
        require('../assets/图片 9@2x.png'),
        require('../assets/图片 10@2x.png')
      ];
      
      // 预加载文字图片
      const textImage = require('../assets/图片 11@2x.png');
      
      images.forEach((src, index) => {
        const img = new Image();
        img.src = src;
        img.onload = () => {
          console.log(`功能图片 ${index + 1} 加载成功`);
        };
        img.onerror = () => {
          console.warn(`功能图片 ${index + 1} 加载失败`);
        };
      });
      
      iconImages.forEach((src, index) => {
        const img = new Image();
        img.src = src;
        img.onload = () => {
          console.log(`图标图片 ${index + 1} 加载成功`);
        };
        img.onerror = () => {
          console.warn(`图标图片 ${index + 1} 加载失败`);
        };
      });
      
      // 预加载文字图片
      const textImg = new Image();
      textImg.src = textImage;
      textImg.onload = () => {
        console.log('文字图片加载成功');
      };
      textImg.onerror = () => {
        console.warn('文字图片加载失败');
      };
    },
    handleResize() {
      // 处理窗口大小变化，优化背景图片显示
      const container = this.$el;
      if (container) {
        const rect = container.getBoundingClientRect();
        const aspectRatio = rect.width / rect.height;
        
        // 根据屏幕比例调整背景图片显示
        const backgroundElement = container.querySelector('.starry-background');
        if (backgroundElement) {
          if (aspectRatio > 1.5) {
            // 宽屏设备
            backgroundElement.style.backgroundSize = 'cover';
          } else {
            // 竖屏或窄屏设备
            backgroundElement.style.backgroundSize = 'cover';
          }
        }
      }
    },
    enterLounge() {
      // 进入会客厅的逻辑
      this.$emit('enter-lounge');
      console.log('进入云上会客厅');
    },
    viewInfo() {
      // 查看信息的逻辑
      this.$emit('view-info');
      console.log('查看会客厅信息');
    },
    handleTitleClick() {
      // 主标题点击交互
      console.log('主标题被点击');
      this.$emit('title-click');
      // 可以添加更多交互效果，比如显示更多信息
    },
    handleSubtitleClick() {
      // 副标题点击交互
      console.log('副标题被点击');
      this.$emit('subtitle-click');
      // 可以添加更多交互效果，比如显示双鸭山相关信息
    },
    goToCloudRoaming() {
      // 跳转到云上漫游页面
      this.$router.push('/cloud-roaming');
      console.log('跳转到云上漫游页面');
    }
  }
}
</script>

<style scoped>
.cloud-lounge-welcome {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #0a0a0a;
  min-height: 100vh;
  min-width: 100vw;
  animation: fadeIn 1.5s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.welcome-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

.starry-background {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-image: url('./star_background.png');
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  background-attachment: scroll;
  animation: twinkle 6s ease-in-out infinite alternate;
  transform: scale(1);
  transition: transform 0.3s ease;
}

/* 确保背景图片在所有设备上都能正确缩放 */
@media (max-width: 768px) {
  .starry-background {
    background-size: cover;
    background-position: center center;
    transform: scale(1.1);
  }
}

@media (max-width: 480px) {
  .starry-background {
    background-size: cover;
    background-position: center center;
    transform: scale(1.2);
  }
}

@keyframes twinkle {
  0% { opacity: 0.7; }
  100% { opacity: 1; }
}

/* 标题区域 */
.title-section {
  position: relative;
  z-index: 10;
  text-align: center;
  margin-top: 200px;
  margin-bottom: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  gap: 20px;
}

.welcome-title {
  font-family: '优设标题黑', 'YouShe BiaoTi Hei', 'Microsoft YaHei', '微软雅黑', sans-serif;
  font-size: 75px;
  font-weight: bold;
  background: linear-gradient(135deg, #E1F5FE 0%, #B3E5FC 25%, #81D4FA 50%, #4FC3F7 75%, #29B6F6 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0 0 30px 0;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 4px;
  line-height: 1.2;
  animation: fadeInUp 1s ease-out;
  cursor: pointer;
  filter: drop-shadow(0 0 20px rgba(129, 217, 230, 0.3));
}

.welcome-subtitle {
  font-family: '宋体', 'SimSun', 'serif';
  font-size: 28px;
  font-weight: normal;
  color: #ffffff;
  margin: 0;
  text-shadow: 0 0 15px rgba(255, 255, 255, 0.4);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 8px;
  line-height: 1.4;
  animation: fadeInUp 1s ease-out 0.2s both;
  cursor: pointer;
}

.welcome-title:hover {
  transform: scale(1.05);
  background: linear-gradient(135deg, #F3E5F5 0%, #E1BEE7 25%, #CE93D8 50%, #BA68C8 75%, #AB47BC 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 30px rgba(129, 217, 230, 0.6));
}

.welcome-subtitle:hover {
  transform: scale(1.03);
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.6);
}


/* 功能图片区域 */
.features-section {
  position: relative;
  z-index: 10;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 40px;
  flex-wrap: wrap;
  max-width: 1200px;
  width: 100%;
  padding: 20px;
  margin-top: auto;
  margin-bottom: auto;
  padding-top: 20px;
  padding-bottom: 180px;
}

.feature-image {
  position: relative;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  overflow: hidden;
}

.feature-image:hover {
  transform: translateY(-8px);
}

.feature-img {
  max-width: 190px;
  height: auto;
  object-fit: contain;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: block;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.feature-img:hover {
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  filter: brightness(1.05);
}

.feature-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.feature-icon {
  width: 60px;
  height: 60px;
  object-fit: contain;
  margin-bottom: 8px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.feature-text {
  font-family: 'Helvetica Neue', 'Arial', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei Light', '微软雅黑 Light', sans-serif;
  font-size: 20px;
  font-weight: 300;
  color: #ffffff;
  text-align: center;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  margin-top: 8px;
}

.feature-image:hover .feature-icon {
  filter: brightness(1.1);
}

.feature-image:hover .feature-text {
  transform: translateY(-2px);
  filter: brightness(1.1);
  text-shadow: 0 4px 8px rgba(0, 0, 0, 0.4);
}

/* 移除特殊定位，让所有按钮自然对齐 */

/* 响应式设计 */
@media (max-width: 1200px) {
  .features-section {
    gap: 32px;
    padding: 15px;
  }
  
  .feature-img {
    max-width: 170px;
  }
  
  .feature-icon {
    width: 50px;
    height: 50px;
  }
  
  .feature-text {
    font-size: 20px;
  }
  
  .feature-icon {
    width: 50px;
    height: 50px;
    margin-bottom: 6px;
  }
}

@media (max-width: 768px) {
  .welcome-title {
    font-size: 72px;
    letter-spacing: 3px;
    margin-bottom: 25px;
  }
  
  .welcome-subtitle {
    font-size: 22px;
    letter-spacing: 3px;
  }
  
  .title-section {
    margin-top: 180px;
    margin-bottom: 50px;
    padding: 30px 15px;
    gap: 15px;
  }
  
  .features-section {
    flex-direction: row;
    gap: 28px;
    align-items: flex-start;
    flex-wrap: wrap;
    justify-content: center;
    padding: 15px;
    padding-top: 15px;
    padding-bottom: 140px;
  }
  
  .feature-img {
    max-width: 160px;
  }
  
  .feature-icon {
    width: 45px;
    height: 45px;
  }
  
  .feature-text {
    font-size: 20px;
  }
  
  .feature-icon {
    width: 45px;
    height: 45px;
    margin-bottom: 5px;
  }
}

@media (max-width: 480px) {
  .welcome-title {
    font-size: 56px;
    letter-spacing: 2px;
    margin-bottom: 20px;
  }
  
  .welcome-subtitle {
    font-size: 20px;
    letter-spacing: 2px;
  }
  
  .title-section {
    margin-top: 160px;
    margin-bottom: 40px;
    padding: 20px 10px;
    gap: 10px;
  }
  
  .feature-img {
    max-width: 130px;
  }
  
  .feature-icon {
    width: 40px;
    height: 40px;
  }
  
  .feature-text {
    font-size: 20px;
  }
  
  .features-section {
    gap: 24px;
    padding: 10px;
    padding-top: 10px;
    padding-bottom: 100px;
  }
  
  .feature-icon {
    width: 40px;
    height: 40px;
    margin-bottom: 4px;
  }
}
</style>
